package com.gec.mall.repository;

import com.gec.mall.document.EsItem;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.elasticsearch.annotations.Query;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
import org.springframework.stereotype.Repository;

/**
 * @Author: li
 * @Date: 2023/2/15
 * @PACKAGE_NAME:com.gec.mall.repository
 * @Project_Name:mall-parent
 * @VERSION: 1.0.0
 */
@Repository
public interface EsItemRepository extends ElasticsearchRepository<EsItem,Long> {

    Page<EsItem> findByTitleAndBrand(String title,String brand,Pageable pageable);

    @Query("{\n" +
            "    \"multi_match\": {\n" +
            "      \"query\": \"?0\",\n" +
            "      \"fields\": [\"category\",\"title\"]\n" +
            "    }\n" +
            "  }")
    Page<EsItem> findByKeyword(String keyword, Pageable pageable);

    @Query("{\n" +
            "    \"prefix\": {\n" +
            "      \"title\": {\n" +
            "        \"value\": \"?0\"\n" +
            "      }\n" +
            "    }\n" +
            "  }")
    Page<EsItem> findByPrefix(String prefix,Pageable pageable);
}
